package com.example.broadcastrecevicedemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.util.Log;

public class DynamiReceiver extends BroadcastReceiver {

    private static final String TAG = "tag";

    @Override
    public void onReceive(Context context, Intent intent) {
        BatteryManager ba=context.getSystemService(BatteryManager.class);

       String action=intent.getAction();
       switch (action){
           case Intent.ACTION_BATTERY_CHANGED:
               int batterNow=ba.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
               Log.d(TAG,"电池电量"+batterNow);
               break;

           case "com.example.BroadcastRecevice.NORMAL":
               String text=intent.getStringExtra("extra_text");
               Log.d(TAG,"局部广播接收器收到："+text);
               break;
       }
    }
}